package main

import (
	"github.com/gin-gonic/gin"
	"paper-manage/handler"
)

func main() {
	router := gin.Default()
	router.Use(func(ctx *gin.Context) {
		ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
		ctx.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, Accept")
		ctx.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
		if ctx.Request.Method == "OPTIONS" {
			ctx.AbortWithStatus(200)
			return
		}
		ctx.Next()
	})

	api := router.Group("api")
	{
		api.POST("/one", handler.One)
		api.POST("/list", handler.List)
		api.POST("/pic", handler.PicList)
		api.POST("/create", handler.Create)
		api.POST("/change", handler.Change)
		api.POST("/search", handler.Search)
	}

	router.Run(":8200")
}
